package com.bookRecommend.commons;

import lombok.Data;

@Data
public class ResponseUtils {

    private Integer code;
    private String msg;
    private Object data;

    /*
        成功代码标识
     */
    private static final Integer SUCCESS_CODE = 1;
    /*
        错误代码标识
     */
    private static final Integer FAILURE_CODE = 0;

    public ResponseUtils(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /*
        请求成功方法
     */
    public static ResponseUtils success() {
        return new ResponseUtils(SUCCESS_CODE, "请求成功", null);
    }

    public static ResponseUtils success(String msg) {
        return new ResponseUtils(SUCCESS_CODE, msg, null);
    }

    public static ResponseUtils success(String msg, Object data) {
        return new ResponseUtils(SUCCESS_CODE, msg, data);
    }

    /*
        请求失败方法
     */
    public static ResponseUtils failure(String msg) {
        return new ResponseUtils(FAILURE_CODE, msg, null);
    }
}
